import { createRouter,  createWebHistory, } from "vue-router";

// 加载条
import nProgress from "nprogress";
import "nprogress/nprogress.css";
// 关闭小圆圈
nProgress.configure({ showSpinner: false });



// 动态导入(懒加载——可以优化代码的打包体积)
// const App = () => import('../App.vue')
const LoginView = () => import('../views/LoginView.vue')
const RegisterView = () => import('../views/RegisterView.vue')
const ForgePasswordViews = () => import('../views/ForgePasswordViews.vue')

// 路由配置
const routes = [
    {path:'/', component: App, meta: { title: '首页' },},
    { path: "/login", component: LoginView, meta: { title: '登录' }, }, 
    { path: "/register", component: RegisterView, meta: { title: '注册' }, }, 
    { path: "/forgepassword", component: ForgePasswordViews, meta: { title: '忘记密码' }, }, 
];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

// 导航前守卫(保安、门卫)
router.beforeEach((to, from, next) => {
    document.title = to.meta.title
    // 停止网页加载条
    nProgress.start();
    next();
});
// 导航后守卫
router.afterEach((to, from) => {
    // 停止网页加载条
    nProgress.done();
});

export default router;